package com.cg.util;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;

public class TuLingUtils {

	public static String getContent (String info)throws Exception{
		String APPKEY="a27d492a6f8f4848488c80aab5b9216f";
		info=URLEncoder.encode(info, "utf-8");
		String getURL="http://www.tuling123.com/openapi/api?key="+APPKEY+"&info="+info;
	
		URL getUrl=new URL(getURL);
		
		HttpURLConnection connection=(HttpURLConnection) getUrl.openConnection();
		connection.connect();
		

		BufferedReader reader=new BufferedReader(new InputStreamReader(connection.getInputStream(),"UTF-8"));
		StringBuffer sb=new StringBuffer();
		String line="";
		while((line=reader.readLine())!=null){
			sb.append(line);
		}
		reader.close();
		connection.disconnect();
		System.out.println("回复内容:"+sb.toString());
		System.out.println("-----------------------------------end--------------------------------");
		return sb.toString();
	}
     public static void main(String[] args) {
    	 try {
			System.out.println(getContent("你是谁"));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
